#pragma once

#include "DX11Includes.h"
#include "EngineStuff.h"
#include "Camera.h"

//#define DEEPDEBUG
#define MAX_VERTICES 50000

struct ParticleVS
{
	XMFLOAT3 initialPosW;
	XMFLOAT3 initialVelW;
	XMFLOAT2 sizeW;
	float age;
	UINT type;
};

struct cteBuffer
{
    XMFLOAT4 gEyePosW;

    // for when the emit position/direction is varying
    XMFLOAT4 gEmitPosW;
	XMFLOAT4 gEmitDirW;	
	XMFLOAT4 AditionalInfos;    ///(gametime,steptime,max_age,vazio)	
	XMFLOAT4X4 gViewProj;

};


class ParticleSystem
{
public:
	ParticleSystem(void);
	~ParticleSystem(void);
	void Init(void);
	
    //float getAge()const;    
    //void setEmitPos(const D3DXVECTOR3& emitPosW);
    //void setEmitDir(const D3DXVECTOR3& emitDirW);    

    //void reset();
	void update(UINT dt,Camera* cam);
    void draw();	

private:
	bool								firstTime;
	UINT								SOstride;
	UINT								stride;
	ID3D11DepthStencilState*			g_DepthState;
	ID3D11BlendState*					blendState;			
	ID3D11Buffer*						dataBuffer;

	ID3D11Buffer*						mStreamOutVB;
	ID3D11Buffer*						mParticleBuffer;
	ID3D11Buffer*						g_pStagingStreamOutBuffer;

	ID3D11VertexShader*                 g_pVertexShader ;	
	ID3D11GeometryShader*				g_pGeometricShader;
	ID3D11VertexShader*                 DVertexShader ;
	ID3D11PixelShader*                  DPixelShader ;
	ID3D11GeometryShader*				DGeometricShader;

	ID3D11InputLayout*                  g_pVertexLayout ;
	cteBuffer							datacpu;
    ID3D11ShaderResourceView*			mRandomTexRV;
	ID3D11ShaderResourceView*			particleTexRV;
	ID3D11SamplerState*                 g_pSamplerLinear ;
	float								gameTime;
	ID3D11Query*						g_pDeviceStats ;
	ParticleVS*							initialParticles;
	UINT								numParticles;

};
